cmake_minimum_required(VERSION 3.21.2)

execute_process(COMMAND gcc -dumpfullversion -dumpversion OUTPUT_VARIABLE GCC_VERSION)
#message(STATUS "gcc version = ${GCC_VERSION}")

if (GCC_VERSION LESS "4.9.3")
    message(FATAL_ERROR "gcc version need greater than 4.9.3")
endif()

project(gtest_vet_idx)

if (POLICY CMP0048)
    cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)

if (CMAKE_VERSION VERSION_LESS "3.1")
    add_definitions(-std=c++11)
else()
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    if(NOT CYGWIN)
        set(CMAKE_CXX_EXTENSIONS OFF)
    endif()
endif()

execute_process(COMMAND git log -1 --pretty=format:%h . OUTPUT_VARIABLE version)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fprofile-arcs -ftest-coverage -g -O2 -lrt -Wall")

include_directories(./)
include_directories(../include)
include_directories(../include/comm)
include_directories(../include/config_parser)
include_directories(../include/faiss_adapter)
include_directories(../include/rocksdb_adapter)

aux_source_directory(./                          UNITEST_FILES_FUNC)
aux_source_directory(../src                      SRC_FILES_FUNC)
aux_source_directory(../src/config_parser        SRC_FILES_CONFIG_PARSER)
aux_source_directory(../src/faiss_adapter        SRC_FILES_FAISS_ADAPTER)
aux_source_directory(../src/rocksdb_adapter      SRC_FILES_ROCKSDB_ADAPTER)
#message(${UNITEST_FILES_FUNC})

list(REMOVE_ITEM SRC_FILES_FUNC "../src/main.cc")

set(SRC_FILES)
list(APPEND SRC_FILES   ${UNITEST_FILES_FUNC}
                        ${SRC_FILES_FUNC}
                        ${SRC_FILES_CONFIG_PARSER} 
                        ${SRC_FILES_FAISS_ADAPTER}
                        ${SRC_FILES_ROCKSDB_ADAPTER})


link_directories(
    ${PROJECT_SOURCE_DIR}/../../../comm
    ${PROJECT_SOURCE_DIR}/../../../comm/stat
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/faiss/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/jsoncpp/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/rocksdb/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/google/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/google_test/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/attr_api
)

add_executable(gtest_vet_idx  ${SRC_FILES})

target_include_directories(gtest_vet_idx PUBLIC
    ${PROJECT_SOURCE_DIR}/../../../comm
    ${PROJECT_SOURCE_DIR}/../../../comm/stat
    ${PROJECT_SOURCE_DIR}/../../../3rdlib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/faiss
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/jsoncpp/include
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/google_test/include 
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/rocksdb/include
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/rocksdb/logging
)

target_link_libraries(gtest_vet_idx PRIVATE  gtest_main gmock gtest protobuf protoc faiss rocksdb stat common attr_api_64 jsoncpp  ssl pthread dl)
set_target_properties(gtest_vet_idx PROPERTIES RUNTIME_OUTPUT_DIRECTORY "../bin")
install(TARGETS gtest_vet_idx RUNTIME DESTINATION bin)
